<template>
  <!-- 上传厂家证照的表格modal -->
  <div>
    <basic-modal 
        :modalOpt="modal" 
        :buttonText="['','关闭']"
        @onMakeSure="onPush"
        @closeModal="closeModal" 
        :footer="footer" 
        >
      <template #cusBtn>
      </template>
      <template>
        <batch-operat-btn v-if="editable" :isView="false" :addData="true" @onAddData="onAddData">
          <template #cusBtn> </template>
        </batch-operat-btn>
        <a-list-info :infoDatas="infoDatas" />
      </template>
    </basic-modal>
  </div>
</template>

<script>
import basicModal from '@/views/app/biz/common/basicModal'
import aListTable from '@/views/app/biz/common/aListTable'
import aListInfo from '@/views/app/biz/common/aListInfo'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'

import {
  getInfoByPid,
  pushInfo
} from './customersalegoods'

export default {
  components: {
    basicModal,
    aListTable,
    batchOperatBtn,
    aListInfo
  },
  data() {
    return {
      footer:undefined,
      editable:false,
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '审核证照',
        modalWidth: '1000px',
      },
      infoDatas:[
        { title: '客户代码', id: 'keHudm', value:''},
        { title: '客户名称', id: 'keHumc', value:''},
        { title: '中标类型', id: 'zhongBiaolx', value:''},
        { title: '中标号', id: 'zhongBiaoh', value:''},
        { title: '品名', id: 'pinMing',  value:''},
        { title: '通用名', id: 'tongYongm',  value:''},
        { title: '注册证号', id: 'zhuCezh',  value:''},
        { title: '规格', id: 'guiGe',  value:''},
        { title: '型号', id: 'xingHao',  value:''},
        { title: '医保代码', id: 'yiBaodm',  value:''},
        { title: '销售代码', id: 'chanPingdm', value:''},
        { title: '计量单位', id: 'jiLiangdw', value:''},
        { title: '单价(元)', id: 'hanShuidj', value:''},
        { title: '生产企业名称', id: 'shengChanqymc',  value:''},
        { title: '高/低值', id: 'jiaZhisx', value:''},
        { title: '推送状态', id: 'tuiSongzt',  value:''},
      ],
      listdata: [],
      listKey: 0,
      pid: '',
      zzPid:'',
      sysSeq: 0,
      loadings: false,
    }
  },
  computed: {},
  mounted() {},
  methods: {
    // // 弹出模态框
    showModal(val,record) {
      this.pid = val.pid
      this.record=record
      this.modal.modalVisible = true
      this.modal.modalTitle = '查看详情'
      this.getSBypid(val)
      // this.getZZImgBypid(val2)
      
    },
    // 关闭模态详细框
    closeModal() {
      this.modal.modalVisible = false
      this.$emit('close')
    },
    closeModal2() {
      this.modal.modalVisible = false
      this.$emit('ok')
    },
    //
    onAddData() {
      this.$refs.addSellerLicChildModal.addModal(this.pid)
    },

    // 推送
    onPush() {
      this.showConfirm(this.record)
    },
    // 保存详细信息
    showConfirm(val) {
      const that = this;
      this.$confirm({
        title: '是否确认推送？',
        content: '推送成功后请提醒客户审核！',
        onOk() {
          return new Promise((resolve, reject) => {
            resolve(pushInfo(val))
          }).then((res)=>{
            if (res && res.code && res.code === 'C1' && res.data) {
              that.$message.success({ content: '推送成功', duration: 2 })
              that.handleModalSaveOk()
            } else {
              that.$message.error({ content:res.code +'：'+res.message, duration: 2 })
            }
          })
          .catch(() =>{
            that.$message.error({ content:"请求出错", duration: 2 })
          });
        },
        onCancel() {},
      });
    },
    // 得到初始化信息
    async getSBypid(val) {
      let res = await getInfoByPid(val)
      if (res && res.code && res.code === 'C1') {
        this.sysSeq = res.data.sysSeq
        for (const key in res.data) {
            for (const item of this.infoDatas) {
                if(key==item.id){
                    item.value=res.data[key]
                }
            }
        }
      }
    },
    // 得到初始化证照图片信息
    // async getZZImgBypid(val2) {
    //   this.loading=true
    //   let pa = {
    //     zhengZhaoPid: val2,
    //   }
    //   let res = await getZZImgByzzpid(pa)
    //   if (res && res.code && res.code === 'C1' && res.data) {
    //     this.listdata = res.data
    //     this.loading=false
    //   }
    //   console.log(res)
    // },
  },
}
</script>

<style>
.recordBox {
  width: 100%;
  min-height: 80px;
}
</style>